#  魔术方法  magic method
#  特殊方法   __nnn__

# 例如 : __init__  类初始化时调用

class People:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def run(self):
        print('People  run')

    def __len__(self):
        print('走len')
        return 5

    def __str__(self):  # 打印
        print('走__str__.....')
        return 'name:{},age{}'.format(self.name,self.age)

    def __repr__(self):  # 控制台交互
        return  'name:{},age{}'.format(self.name,self.age)

    def __add__(self, other):
        print('走__add__加........')
        return self.age + other.age

    def __sub__(self, other):
        print('走 __sub__ 减.......')
        return self.age - other.age

    def __lt__(self, other):  # less than (小于)
        print('less than  小于....')
        return self.age < other.age

    def __gt__(self, other):  # geater than
        print('geater  than  大于.......')
        return self.age > other.age

    def __abs__(self):         #  absolute value   绝对值
        if self.age < 0:
            return -self.age
        return self.age

    def __bool__(self):
        return self.age > 0

    def __call__(self,friends):
        print('My name is {}'.format(self.name))
        print('My friend is {}'.format((friends)))



# print(People('张三',-12))


p1 = People('张三',-12)
p1('Tim')
# #  print(len(p1))    Flase
# print(len(p1))
# p1.__len__()
#
# print('-----str------>')
# print(p1)

# print('-----add------>')
# p2 = People('李四',14)
# print(p1+p2)
#
# print('-----sub------>')
# print(p2-p1)
#
# print('-----less than------>')
# print(p1 < p2)
#
# print('-----geater  than------>')
# # print(p1.__gt__(p2))
#
# print('-----bool------>')
# print(bool(p1))












